<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="datetime-time.html" />
<link rel="prev" href="datetime-date.html" />
<link rel="parent" href="module-datetime.html" />
<link rel="next" href="datetime-time.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>5.1.4 datetime Objects </title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="5.1.3 date Objects"
  href="datetime-date.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="5.1 datetime  "
  href="module-datetime.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="5.1.5 time Objects"
  href="datetime-time.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="datetime-date.html">5.1.3 date Objects</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-datetime.html">5.1 datetime  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="datetime-time.html">5.1.5 time Objects</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h2><a name="SECTION007140000000000000000"></a><a name="datetime-datetime"></a>
<br>
5.1.4 <tt class="class">datetime</tt> Objects 
</h2>

<p>
A <tt class="class">datetime</tt> object is a single object containing all the
information from a <tt class="class">date</tt> object and a <tt class="class">time</tt> object.  Like a
<tt class="class">date</tt> object, <tt class="class">datetime</tt> assumes the current Gregorian
calendar extended in both directions; like a time object,
<tt class="class">datetime</tt> assumes there are exactly 3600*24 seconds in every
day.

<p>
Constructor:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-634' xml:id='l2h-634' class="class">datetime</tt></b>(</nobr></td>
  <td><var>year, month, day</var><big>[</big><var>,
                            hour</var><big>[</big><var>, minute</var><big>[</big><var>,
                            second</var><big>[</big><var>, microsecond</var><big>[</big><var>,
                            tzinfo</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  The year, month and day arguments are required.  <var>tzinfo</var> may
  be <code>None</code>, or an instance of a <tt class="class">tzinfo</tt> subclass.  The
  remaining arguments may be ints or longs, in the following ranges:

<p>

<ul>
<li><code>MINYEAR &lt;= <var>year</var> &lt;= MAXYEAR</code>
</li>
<li><code>1 &lt;= <var>month</var> &lt;= 12</code>
</li>
<li><code>1 &lt;= <var>day</var> &lt;= number of days in the given month and year</code>
</li>
<li><code>0 &lt;= <var>hour</var> &lt; 24</code>
</li>
<li><code>0 &lt;= <var>minute</var> &lt; 60</code>
</li>
<li><code>0 &lt;= <var>second</var> &lt; 60</code>
</li>
<li><code>0 &lt;= <var>microsecond</var> &lt; 1000000</code>
  
</li>
</ul>

<p>
If an argument outside those ranges is given,
  <tt class="exception">ValueError</tt> is raised.
</dl>

<p>
Other constructors, all class methods:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-635' xml:id='l2h-635' class="method">today</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return the current local datetime, with <tt class="member">tzinfo</tt> <code>None</code>.
  This is equivalent to
  <code>datetime.fromtimestamp(time.time())</code>.
  See also <tt class="method">now()</tt>, <tt class="method">fromtimestamp()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-636' xml:id='l2h-636' class="method">now</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>tz</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return the current local date and time.  If optional argument
  <var>tz</var> is <code>None</code> or not specified, this is like
  <tt class="method">today()</tt>, but, if possible, supplies more precision than can
  be gotten from going through a <tt class="function">time.time()</tt> timestamp (for
  example, this may be possible on platforms supplying the C
  <tt class="cfunction">gettimeofday()</tt> function).

<p>
Else <var>tz</var> must be an instance of a class <tt class="class">tzinfo</tt> subclass,
  and the current date and time are converted to <var>tz</var>'s time
  zone.  In this case the result is equivalent to
  <code><var>tz</var>.fromutc(datetime.utcnow().replace(tzinfo=<var>tz</var>))</code>.
  See also <tt class="method">today()</tt>, <tt class="method">utcnow()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-637' xml:id='l2h-637' class="method">utcnow</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return the current UTC date and time, with <tt class="member">tzinfo</tt> <code>None</code>.
  This is like <tt class="method">now()</tt>, but returns the current UTC date and time,
  as a naive <tt class="class">datetime</tt> object.
  See also <tt class="method">now()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-638' xml:id='l2h-638' class="method">fromtimestamp</tt></b>(</nobr></td>
  <td><var>timestamp</var><big>[</big><var>, tz</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return the local date and time corresponding to the POSIX
  timestamp, such as is returned by <tt class="function">time.time()</tt>.
  If optional argument <var>tz</var> is <code>None</code> or not specified, the
  timestamp is converted to the platform's local date and time, and
  the returned <tt class="class">datetime</tt> object is naive.

<p>
Else <var>tz</var> must be an instance of a class <tt class="class">tzinfo</tt> subclass,
  and the timestamp is converted to <var>tz</var>'s time zone.  In this case
  the result is equivalent to
  <code><var>tz</var>.fromutc(datetime.utcfromtimestamp(<var>timestamp</var>).replace(tzinfo=<var>tz</var>))</code>.

<p>
<tt class="method">fromtimestamp()</tt> may raise <tt class="exception">ValueError</tt>, if the
  timestamp is out of the range of values supported by the platform C
  <tt class="cfunction">localtime()</tt> or <tt class="cfunction">gmtime()</tt> functions.  It's common
  for this to be restricted to years in 1970 through 2038.
  Note that on non-POSIX systems that include leap seconds in their
  notion of a timestamp, leap seconds are ignored by
  <tt class="method">fromtimestamp()</tt>, and then it's possible to have two timestamps
  differing by a second that yield identical <tt class="class">datetime</tt> objects.
  See also <tt class="method">utcfromtimestamp()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-639' xml:id='l2h-639' class="method">utcfromtimestamp</tt></b>(</nobr></td>
  <td><var>timestamp</var>)</td></tr></table></dt>
<dd>
  Return the UTC <tt class="class">datetime</tt> corresponding to the POSIX
  timestamp, with <tt class="member">tzinfo</tt> <code>None</code>.
  This may raise <tt class="exception">ValueError</tt>, if the
  timestamp is out of the range of values supported by the platform
  C <tt class="cfunction">gmtime()</tt> function.  It's common for this to be
  restricted to years in 1970 through 2038.
  See also <tt class="method">fromtimestamp()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-640' xml:id='l2h-640' class="method">fromordinal</tt></b>(</nobr></td>
  <td><var>ordinal</var>)</td></tr></table></dt>
<dd>
  Return the <tt class="class">datetime</tt> corresponding to the proleptic
  Gregorian ordinal, where January 1 of year 1 has ordinal 1.
  <tt class="exception">ValueError</tt> is raised unless <code>1 &lt;= ordinal &lt;=
  datetime.max.toordinal()</code>.  The hour, minute, second and
  microsecond of the result are all 0,
  and <tt class="member">tzinfo</tt> is <code>None</code>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-641' xml:id='l2h-641' class="method">combine</tt></b>(</nobr></td>
  <td><var>date, time</var>)</td></tr></table></dt>
<dd>
  Return a new <tt class="class">datetime</tt> object whose date members are
  equal to the given <tt class="class">date</tt> object's, and whose time
  and <tt class="member">tzinfo</tt> members are equal to the given <tt class="class">time</tt> object's.
  For any <tt class="class">datetime</tt> object <var>d</var>, <code><var>d</var> ==
  datetime.combine(<var>d</var>.date(), <var>d</var>.timetz())</code>.  If date is a
  <tt class="class">datetime</tt> object, its time and <tt class="member">tzinfo</tt> members are
  ignored.
  </dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-642' xml:id='l2h-642' class="method">strptime</tt></b>(</nobr></td>
  <td><var>date_string, format</var>)</td></tr></table></dt>
<dd>
  Return a <tt class="class">datetime</tt> corresponding to <var>date_string</var>, parsed
  according to <var>format</var>.  This is equivalent to
  <code>datetime(*(time.strptime(date_string,
  format)[0:6]))</code>. <tt class="exception">ValueError</tt> is raised if the date_string and
  format can't be parsed by <tt class="function">time.strptime()</tt> or if it returns a
  value which isn't a time tuple.

<p>

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
Class attributes:

<p>
<dl><dt><b><tt id='l2h-643' xml:id='l2h-643' class="member">min</tt></b></dt>
<dd>
  The earliest representable <tt class="class">datetime</tt>,
  <code>datetime(MINYEAR, 1, 1, tzinfo=None)</code>.
</dl>

<p>
<dl><dt><b><tt id='l2h-644' xml:id='l2h-644' class="member">max</tt></b></dt>
<dd>
  The latest representable <tt class="class">datetime</tt>,
  <code>datetime(MAXYEAR, 12, 31, 23, 59, 59, 999999, tzinfo=None)</code>.
</dl>

<p>
<dl><dt><b><tt id='l2h-645' xml:id='l2h-645' class="member">resolution</tt></b></dt>
<dd>
  The smallest possible difference between non-equal <tt class="class">datetime</tt>
  objects, <code>timedelta(microseconds=1)</code>.
</dl>

<p>
Instance attributes (read-only):

<p>
<dl><dt><b><tt id='l2h-646' xml:id='l2h-646' class="member">year</tt></b></dt>
<dd>
  Between <tt class="constant">MINYEAR</tt> and <tt class="constant">MAXYEAR</tt> inclusive.
</dl>

<p>
<dl><dt><b><tt id='l2h-647' xml:id='l2h-647' class="member">month</tt></b></dt>
<dd>
  Between 1 and 12 inclusive.
</dl>

<p>
<dl><dt><b><tt id='l2h-648' xml:id='l2h-648' class="member">day</tt></b></dt>
<dd>
  Between 1 and the number of days in the given month of the given
  year.
</dl>

<p>
<dl><dt><b><tt id='l2h-649' xml:id='l2h-649' class="member">hour</tt></b></dt>
<dd>
  In <code>range(24)</code>.
</dl>

<p>
<dl><dt><b><tt id='l2h-650' xml:id='l2h-650' class="member">minute</tt></b></dt>
<dd>
  In <code>range(60)</code>.
</dl>

<p>
<dl><dt><b><tt id='l2h-651' xml:id='l2h-651' class="member">second</tt></b></dt>
<dd>
  In <code>range(60)</code>.
</dl>

<p>
<dl><dt><b><tt id='l2h-652' xml:id='l2h-652' class="member">microsecond</tt></b></dt>
<dd>
  In <code>range(1000000)</code>.
</dl>

<p>
<dl><dt><b><tt id='l2h-653' xml:id='l2h-653' class="member">tzinfo</tt></b></dt>
<dd>
  The object passed as the <var>tzinfo</var> argument to the
  <tt class="class">datetime</tt> constructor, or <code>None</code> if none was passed.
</dl>

<p>
Supported operations:

<p>
<div class="center"><table class="realtable">
  <thead>
    <tr>
      <th class="center">Operation</th>
      <th class="left"  >Result</th>
      </tr>
    </thead>
  <tbody>
    <tr><td class="center" valign="baseline"><code><var>datetime2</var> = <var>datetime1</var> + <var>timedelta</var></code></td>
        <td class="left"  >(1)</td></tr><p>

    <tr><td class="center" valign="baseline"><code><var>datetime2</var> = <var>datetime1</var> - <var>timedelta</var></code></td>
        <td class="left"  >(2)</td></tr><p>

    <tr><td class="center" valign="baseline"><code><var>timedelta</var> = <var>datetime1</var> - <var>datetime2</var></code></td>
        <td class="left"  >(3)</td></tr><p>

    <tr><td class="center" valign="baseline"><code><var>datetime1</var> &lt; <var>datetime2</var></code></td>
        <td class="left"  >Compares <tt class="class">datetime</tt> to <tt class="class">datetime</tt>.
    (4)</td></tr><p>

    </tbody>
</table></div>

<p>
<dl>
<dt><strong>(1)</strong></dt>
<dd><p>
datetime2 is a duration of timedelta removed from datetime1, moving
    forward in time if <code><var>timedelta</var>.days</code> &gt; 0, or backward if
    <code><var>timedelta</var>.days</code> &lt; 0.  The result has the same <tt class="member">tzinfo</tt> member
    as the input datetime, and datetime2 - datetime1 == timedelta after.
    <tt class="exception">OverflowError</tt> is raised if datetime2.year would be
    smaller than <tt class="constant">MINYEAR</tt> or larger than <tt class="constant">MAXYEAR</tt>.
    Note that no time zone adjustments are done even if the input is an
    aware object.

<p>
</dd>
<dt><strong>(2)</strong></dt>
<dd>Computes the datetime2 such that datetime2 + timedelta == datetime1.
    As for addition, the result has the same <tt class="member">tzinfo</tt> member
    as the input datetime, and no time zone adjustments are done even
    if the input is aware.
    This isn't quite equivalent to datetime1 + (-timedelta), because
    -timedelta in isolation can overflow in cases where
    datetime1 - timedelta does not.

<p>
</dd>
<dt><strong>(3)</strong></dt>
<dd>Subtraction of a <tt class="class">datetime</tt> from a
    <tt class="class">datetime</tt> is defined only if both
    operands are naive, or if both are aware.  If one is aware and the
    other is naive, <tt class="exception">TypeError</tt> is raised.

<p>
If both are naive, or both are aware and have the same <tt class="member">tzinfo</tt>
    member, the <tt class="member">tzinfo</tt> members are ignored, and the result is
    a <tt class="class">timedelta</tt> object <var>t</var> such that
    <code><var>datetime2</var> + <var>t</var> == <var>datetime1</var></code>.  No time zone
    adjustments are done in this case.

<p>
If both are aware and have different <tt class="member">tzinfo</tt> members,
    <code>a-b</code> acts as if <var>a</var> and <var>b</var> were first converted to
    naive UTC datetimes first.  The result is
    <code>(<var>a</var>.replace(tzinfo=None) - <var>a</var>.utcoffset()) -
          (<var>b</var>.replace(tzinfo=None) - <var>b</var>.utcoffset())</code>
    except that the implementation never overflows.

<p>
</dd>
<dt><strong>(4)</strong></dt>
<dd><p>
<var>datetime1</var> is considered less than <var>datetime2</var>
when <var>datetime1</var> precedes <var>datetime2</var> in time.

<p>
If one comparand is naive and
the other is aware, <tt class="exception">TypeError</tt> is raised.  If both
    comparands are aware, and have the same <tt class="member">tzinfo</tt> member,
    the common <tt class="member">tzinfo</tt> member is ignored and the base datetimes
    are compared.  If both comparands are aware and have different
    <tt class="member">tzinfo</tt> members, the comparands are first adjusted by
    subtracting their UTC offsets (obtained from <code>self.utcoffset()</code>).
    <span class="note"><b class="label">Note:</b>
In order to stop comparison from falling back to the default
          scheme of comparing object addresses, datetime comparison
          normally raises <tt class="exception">TypeError</tt> if the other comparand
          isn't also a <tt class="class">datetime</tt> object.  However,
          <code>NotImplemented</code> is returned instead if the other comparand
          has a <tt class="method">timetuple</tt> attribute.  This hook gives other
          kinds of date objects a chance at implementing mixed-type
          comparison.  If not, when a <tt class="class">datetime</tt> object is
          compared to an object of a different type, <tt class="exception">TypeError</tt>
          is raised unless the comparison is <code>==</code> or <code>!=</code>.  The
          latter cases return <tt class="constant">False</tt> or <tt class="constant">True</tt>,
          respectively.</span>

<p>
</dd>
</dl>

<p>
<tt class="class">datetime</tt> objects can be used as dictionary keys. In Boolean
contexts, all <tt class="class">datetime</tt> objects are considered to be true.

<p>
Instance methods:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-654' xml:id='l2h-654' class="method">date</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return <tt class="class">date</tt> object with same year, month and day.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-655' xml:id='l2h-655' class="method">time</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return <tt class="class">time</tt> object with same hour, minute, second and microsecond.
  <tt class="member">tzinfo</tt> is <code>None</code>.  See also method <tt class="method">timetz()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-656' xml:id='l2h-656' class="method">timetz</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return <tt class="class">time</tt> object with same hour, minute, second, microsecond,
  and tzinfo members.  See also method <tt class="method">time()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-657' xml:id='l2h-657' class="method">replace</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>year</var><big>[</big><var>, month</var><big>[</big><var>,
                            day</var><big>[</big><var>, hour</var><big>[</big><var>, minute</var><big>[</big><var>,
                            second</var><big>[</big><var>, microsecond</var><big>[</big><var>,
                            tzinfo</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return a datetime with the same members, except for those members given
  new values by whichever keyword arguments are specified.  Note that
  <code>tzinfo=None</code> can be specified to create a naive datetime from
  an aware datetime with no conversion of date and time members.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-658' xml:id='l2h-658' class="method">astimezone</tt></b>(</nobr></td>
  <td><var>tz</var>)</td></tr></table></dt>
<dd>
  Return a <tt class="class">datetime</tt> object with new <tt class="member">tzinfo</tt> member
  <var>tz</var>, adjusting the date and time members so the result is the
  same UTC time as <var>self</var>, but in <var>tz</var>'s local time.

<p>
<var>tz</var> must be an instance of a <tt class="class">tzinfo</tt> subclass, and its
  <tt class="method">utcoffset()</tt> and <tt class="method">dst()</tt> methods must not return
  <code>None</code>.  <var>self</var> must be aware (<code><var>self</var>.tzinfo</code> must
  not be <code>None</code>, and <code><var>self</var>.utcoffset()</code> must not return
  <code>None</code>).

<p>
If <code><var>self</var>.tzinfo</code> is <var>tz</var>,
  <code><var>self</var>.astimezone(<var>tz</var>)</code> is equal to <var>self</var>:  no
  adjustment of date or time members is performed.
  Else the result is local time in time zone <var>tz</var>, representing the
  same UTC time as <var>self</var>:  after <code><var>astz</var> =
  <var>dt</var>.astimezone(<var>tz</var>)</code>,
  <code><var>astz</var> - <var>astz</var>.utcoffset()</code> will usually have the same
  date and time members as <code><var>dt</var> - <var>dt</var>.utcoffset()</code>.
  The discussion of class <tt class="class">tzinfo</tt> explains the cases at Daylight
  Saving Time transition boundaries where this cannot be achieved (an issue
  only if <var>tz</var> models both standard and daylight time).

<p>
If you merely want to attach a time zone object <var>tz</var> to a
  datetime <var>dt</var> without adjustment of date and time members,
  use <code><var>dt</var>.replace(tzinfo=<var>tz</var>)</code>.  If
  you merely want to remove the time zone object from an aware datetime
  <var>dt</var> without conversion of date and time members, use
  <code><var>dt</var>.replace(tzinfo=None)</code>.

<p>
Note that the default <tt class="method">tzinfo.fromutc()</tt> method can be overridden
  in a <tt class="class">tzinfo</tt> subclass to affect the result returned by
  <tt class="method">astimezone()</tt>.  Ignoring error cases, <tt class="method">astimezone()</tt>
  acts like:

<p>
<div class="verbatim"><pre>
  def astimezone(self, tz):
      if self.tzinfo is tz:
          return self
      # Convert self to UTC, and attach the new time zone object.
      utc = (self - self.utcoffset()).replace(tzinfo=tz)
      # Convert from UTC to tz's local time.
      return tz.fromutc(utc)
</pre></div>
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-659' xml:id='l2h-659' class="method">utcoffset</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  If <tt class="member">tzinfo</tt> is <code>None</code>, returns <code>None</code>, else
  returns <code><var>self</var>.tzinfo.utcoffset(<var>self</var>)</code>, and
  raises an exception if the latter doesn't return <code>None</code>, or
  a <tt class="class">timedelta</tt> object representing a whole number of minutes
  with magnitude less than one day.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-660' xml:id='l2h-660' class="method">dst</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  If <tt class="member">tzinfo</tt> is <code>None</code>, returns <code>None</code>, else
  returns <code><var>self</var>.tzinfo.dst(<var>self</var>)</code>, and
  raises an exception if the latter doesn't return <code>None</code>, or
  a <tt class="class">timedelta</tt> object representing a whole number of minutes
  with magnitude less than one day.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-661' xml:id='l2h-661' class="method">tzname</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  If <tt class="member">tzinfo</tt> is <code>None</code>, returns <code>None</code>, else
  returns <code><var>self</var>.tzinfo.tzname(<var>self</var>)</code>,
  raises an exception if the latter doesn't return <code>None</code> or
  a string object,
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-662' xml:id='l2h-662' class="method">timetuple</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return a <tt class="class">time.struct_time</tt> such as returned by
  <tt class="function">time.localtime()</tt>.
  <code><var>d</var>.timetuple()</code> is equivalent to
  <code>time.struct_time((<var>d</var>.year, <var>d</var>.month, <var>d</var>.day,
         <var>d</var>.hour, <var>d</var>.minute, <var>d</var>.second,
         <var>d</var>.weekday(),
         <var>d</var>.toordinal() - date(<var>d</var>.year, 1, 1).toordinal() + 1,
         dst))</code>
  The <tt class="member">tm_isdst</tt> flag of the result is set according to
  the <tt class="method">dst()</tt> method:  <tt class="member">tzinfo</tt> is <code>None</code> or
  <tt class="method">dst()</tt> returns <code>None</code>,
  <tt class="member">tm_isdst</tt> is set to  <code>-1</code>; else if <tt class="method">dst()</tt> returns
  a non-zero value, <tt class="member">tm_isdst</tt> is set to <code>1</code>;
  else <code>tm_isdst</code> is set to <code>0</code>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-663' xml:id='l2h-663' class="method">utctimetuple</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  If <tt class="class">datetime</tt> instance <var>d</var> is naive, this is the same as
  <code><var>d</var>.timetuple()</code> except that <tt class="member">tm_isdst</tt> is forced to 0
  regardless of what <code>d.dst()</code> returns.  DST is never in effect
  for a UTC time.

<p>
If <var>d</var> is aware, <var>d</var> is normalized to UTC time, by subtracting
  <code><var>d</var>.utcoffset()</code>, and a <tt class="class">time.struct_time</tt> for the
  normalized time is returned.  <tt class="member">tm_isdst</tt> is forced to 0.
  Note that the result's <tt class="member">tm_year</tt> member may be
  <tt class="constant">MINYEAR</tt>-1 or <tt class="constant">MAXYEAR</tt>+1, if <var>d</var>.year was
  <code>MINYEAR</code> or <code>MAXYEAR</code> and UTC adjustment spills over a
  year boundary.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-664' xml:id='l2h-664' class="method">toordinal</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return the proleptic Gregorian ordinal of the date.  The same as
  <code>self.date().toordinal()</code>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-665' xml:id='l2h-665' class="method">weekday</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return the day of the week as an integer, where Monday is 0 and
  Sunday is 6.  The same as <code>self.date().weekday()</code>.
  See also <tt class="method">isoweekday()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-666' xml:id='l2h-666' class="method">isoweekday</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return the day of the week as an integer, where Monday is 1 and
  Sunday is 7.  The same as <code>self.date().isoweekday()</code>.
  See also <tt class="method">weekday()</tt>, <tt class="method">isocalendar()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-667' xml:id='l2h-667' class="method">isocalendar</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return a 3-tuple, (ISO year, ISO week number, ISO weekday).  The
  same as <code>self.date().isocalendar()</code>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-668' xml:id='l2h-668' class="method">isoformat</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>sep</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Return a string representing the date and time in ISO 8601 format,
      YYYY-MM-DDTHH:MM:SS.mmmmmm
  or, if <tt class="member">microsecond</tt> is 0,
      YYYY-MM-DDTHH:MM:SS

<p>
If <tt class="method">utcoffset()</tt> does not return <code>None</code>, a 6-character
  string is appended, giving the UTC offset in (signed) hours and
  minutes:
      YYYY-MM-DDTHH:MM:SS.mmmmmm+HH:MM
  or, if <tt class="member">microsecond</tt> is 0
      YYYY-MM-DDTHH:MM:SS+HH:MM

<p>
The optional argument <var>sep</var> (default <code>'T'</code>) is a
  one-character separator, placed between the date and time portions
  of the result.  For example,

<p>
<div class="verbatim"><pre>
&gt;&gt;&gt; from datetime import tzinfo, timedelta, datetime
&gt;&gt;&gt; class TZ(tzinfo):
...     def utcoffset(self, dt): return timedelta(minutes=-399)
...
&gt;&gt;&gt; datetime(2002, 12, 25, tzinfo=TZ()).isoformat(' ')
'2002-12-25 00:00:00-06:39'
</pre></div>
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-669' xml:id='l2h-669' class="method">__str__</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  For a <tt class="class">datetime</tt> instance <var>d</var>, <code>str(<var>d</var>)</code> is
  equivalent to <code><var>d</var>.isoformat(' ')</code>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-670' xml:id='l2h-670' class="method">ctime</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
  Return a string representing the date and time, for example
  <code>datetime(2002, 12, 4, 20, 30, 40).ctime() ==
   'Wed Dec  4 20:30:40 2002'</code>.
  <code>d.ctime()</code> is equivalent to
  <code>time.ctime(time.mktime(d.timetuple()))</code> on platforms where
  the native C <tt class="cfunction">ctime()</tt> function (which
  <tt class="function">time.ctime()</tt> invokes, but which
  <tt class="method">datetime.ctime()</tt> does not invoke) conforms to the C
  standard.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-671' xml:id='l2h-671' class="method">strftime</tt></b>(</nobr></td>
  <td><var>format</var>)</td></tr></table></dt>
<dd>
  Return a string representing the date and time, controlled by an
  explicit format string.  See section&nbsp;<a href="strftime-behavior.html#strftime-behavior">5.1.7</a> -
  <tt class="method">strftime()</tt> behavior.
</dl>

<p>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="5.1.3 date Objects"
  href="datetime-date.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="5.1 datetime  "
  href="module-datetime.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="5.1.5 time Objects"
  href="datetime-time.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="datetime-date.html">5.1.3 date Objects</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-datetime.html">5.1 datetime  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="datetime-time.html">5.1.5 time Objects</a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
